package com.TeamJigsaw.DanteTrail.Presenters;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.TeamJigsaw.DanteTrail.Debug.Debug;
import com.TeamJigsaw.DanteTrail.Models.Party;
import com.TeamJigsaw.DanteTrail.Views.MainViewFrame;
import com.TeamJigsaw.DanteTrail.Views.Interfaces.TownViewInterface;
/**
 * Represents a controller for the Town Checkpoint
 * @author Victor
 *
 */
public class TownViewController implements ViewController{
	private Party party;
	private MainViewFrame mainView;
	private TownViewInterface town;
	private GameViewController game;
	private String name;
	public TownViewController(Party party, MainViewFrame mainView, GameViewController game, String name){
		this.party = party;
		this.mainView = mainView;
		this.game = game;
		this.name = name;
		town = this.mainView.getTownView();
		if(!town.listenersExist())
			createListeners();
	}
	/**
	 * Creates the listeners needed for the components in the view
	 */
	@Override
	public void createListeners() {
		Debug.println("in createListeners: "+this, Debug.M_NINE_DEMO);
		ActionListener shopListen = new ShopButtonListener(this);
		ActionListener restListen = new RestButtonListener();
		ActionListener tradeListen = new TradeButtonListener();
		ActionListener proceedListen = new ProceedButtonListener();
		ActionListener partyInfoListen = new PartyInfoButtonListener();
		town.setShopButtonListener(shopListen);
		town.setRestButtonListener(restListen);
		//Will be readded once the interface is changed
		//town.setTradeButtonListener(tradeListen);
		town.setProceedButtonListener(proceedListen);
		
	}
	
	public TownViewInterface getTownView(){
		return town;
	}
	public String getName(){
		return name;
	}
	
	private class ShopButtonListener implements ActionListener {
		private TownViewController tvc;
		public ShopButtonListener(TownViewController tvc){
			this.tvc = tvc;
		}
		@Override
		public void actionPerformed(ActionEvent e) {
			Debug.println("The ShopButton was pressed", Debug.M_NINE_DEMO);
			System.out.println("ShopButton");
			((CardLayout) mainView.getContentPane().getLayout()).show(mainView.getContentPane(), "Shop");
			mainView.setTitle("Shop");
			ShopViewController svc = new ShopViewController(party, mainView, tvc);
			svc.setInventoryLabels();
		}
	}
	
	private class RestButtonListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {

		}
	}
	
	private class TradeButtonListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			//Put a JOptionPane here
		}
	}
	
	private class ProceedButtonListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			Debug.println("The ProceedButton was pressed", Debug.M_NINE_DEMO);
			System.out.println("ShopButton");
			mainView.getTownView().removeListeners();
			((CardLayout) mainView.getContentPane().getLayout()).show(mainView.getContentPane(), "Game");
			mainView.setTitle("Trail");
			GameViewController gvc = new GameViewController(party, mainView);
			

		}
	}
	
	private class PartyInfoButtonListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {

		}
	}
	
	
	/*
	 * private class ShopButtonListener implements ActionListener {
		private TownViewController tvc;
		public ShopButtonListener(TownViewController tvc){
			this.tvc = tvc;
		}
		@Override
		public void actionPerformed(ActionEvent e) {
			tvc = TownViewController.this;
			ShopViewController svc = new ShopViewController(party, mainView, tvc);

		}
	}
	 */
}
